package Test;

import java.io.FileNotFoundException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;

/**
 * @author Alger
 * @date 2021/8/31  17:48
 */
public class Test6 {
    public static Map<String, Integer> dateRelationMap = new HashMap() {{
        put("d", Calendar.DAY_OF_MONTH);
        put("h", Calendar.HOUR_OF_DAY);
        put("m", Calendar.MINUTE);
        put("s", Calendar.SECOND);
    }};
    public static void main(String[] args) throws FileNotFoundException {
        int i = dateFormat2("2d 2h 2s");
        System.out.println(i);
    }

    public static int dateFormat2(String dateString) {
        int datetrans = 0;
        int d = 0;
        int h = 0;
        int s = 0;

        String[] items = dateString.split("\\s+");
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Calendar calendar = Calendar.getInstance();
        for (String item : items) {
            item = item.trim();
            if (item.endsWith("d")) {
                d = Integer.parseInt(item.split("d")[0]);
                d = d * 24 * 60 * 60;
            }
            if (item.endsWith("h")) {
                h = Integer.parseInt(item.split("h")[0]);
                h = h * 60 * 60;

            }
            if (item.endsWith("s")) {
                s = Integer.parseInt(item.split("s")[0]);
            }
            datetrans = d + h + s;
        }
        return datetrans;
    }
}
